package com.golddaymicromall.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.golddaymicromall.activity.profit.ProfitDetailActivity;
import com.golddaymicromall.activity.R;
import com.golddaymicromall.bean.ProfitInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/3 0003.
 */
public class ProfitAdapter extends BaseAdapter {

    private List<ProfitInfo> list = new ArrayList<ProfitInfo>();
    private Context ctx;
    LayoutInflater layoutinflater;

    public ProfitAdapter(List<ProfitInfo> list, Context ctx) {
        this.list = list;
        this.ctx = ctx;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        View view = convertView;
        if (view == null) {
            holder = new ViewHolder();
            layoutinflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = layoutinflater.inflate(R.layout.item_profit, null);
            holder.mCycleNo = (TextView) view.findViewById(R.id.profit_cycleNo);
            holder.mCommission = (TextView) view.findViewById(R.id.profit_commission);
            holder.mYugou = (TextView) view.findViewById(R.id.profit_yugou);
            holder.mProfit = (TextView) view.findViewById(R.id.profit_Profit);
            holder.mDetails = (Button) view.findViewById(R.id.profit_details);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        if (list.size() > 0) {
            holder.mCycleNo.setText(list.get(position).getPeriod());
            holder.mCommission.setText(list.get(position).getBonuszr().toString());
            holder.mYugou.setText(list.get(position).getBonuswallet().toString());
            holder.mProfit.setText(list.get(position).getTotalget().toString());
        } else {
            Toast.makeText(ctx, "您还没有收益信息", Toast.LENGTH_SHORT).show();
        }
        holder.mDetails.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent_profitdetail = new Intent(ctx, ProfitDetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("zhouqishu",list.get(position).getPeriod());
                bundle.putString("jiesuanshijian",list.get(position).getCaldate().toString());
                bundle.putString("dianpubianhao",list.get(position).getShopno());
                bundle.putString("jiamengleixing",list.get(position).getShopgradename());
                bundle.putString("guanlizhiji",list.get(position).getTggradename());



                bundle.putString("danqishouqi",list.get(position).getTotalbonus().toString());
                bundle.putString("fuchishouyi",list.get(position).getBonusmanager().toString());
                bundle.putString("fuwushouyi",list.get(position).getBonusrecomme().toString());
                bundle.putString("zhuoyueshouyi",list.get(position).getBonusexcelle().toString());
                bundle.putString("kaifashouyi",list.get(position).getBonuszr().toString());
                bundle.putString("rongyaoshouyi",list.get(position).getBonus_excellentstar().toString());

                bundle.putString("yugoudaikuan",list.get(position).getBonuswallet().toString());
                bundle.putString("shijishouru",list.get(position).getTotalget().toString());


                bundle.putString("Allinte",list.get(position).getAllinte().toString());
                intent_profitdetail.putExtras(bundle);
                ctx.startActivity(intent_profitdetail);
            }
        });
        return view;
    }

    private class ViewHolder {
        TextView mCycleNo;
        TextView mCommission;
        TextView mYugou;
        TextView mProfit;
        Button mDetails;
    }
}
